﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.IO;
using System.Linq;

namespace ScanSnap.Domain
{
    [System.Runtime.Serialization.DataContract]
    public class Organization
    {
        [System.Runtime.Serialization.DataMember(Name = "id")]
        public string Id { get; set; }

        [System.Runtime.Serialization.DataMember(Name = "code")]
        public string Code { get; set; }

        [System.Runtime.Serialization.DataMember(Name = "name")]
        public string Name { get; set; }

        public ObservableCollection<Patient> Patients { get; set; }

        public Organization()
        {
            Patients = new ObservableCollection<Patient>();
            DocumentTypes = new ObservableCollection<DocumentType>();
        }

        public void AddPatient(Patient p)
        {
            Patients.Add(p);
        }

        public ObservableCollection<DocumentType> DocumentTypes { get; set; }

        public void AddDocumentType(string id, string name)
        {
           
            DocumentType dt = new DocumentType { Id = id, Name = name };
    
            string pdfPath = ConfigurationManager.AppSettings["organization_documents"];

            DirectoryInfo info = new DirectoryInfo(@pdfPath + "\\" + name);

            if (!Directory.Exists(@pdfPath + "\\" + name))
                return;

            List<FileInfo> list = info.GetFiles("*.pdf").OrderByDescending(p => p.CreationTime).ToList();

            /*
            for (int i = 0; i < list.Count; i++)
            {
                d = new Document { Id = list[i].FullName, Name = list[i].Name, DocumentName = list[i].Name, DocumentDate = list[i].CreationTime };
                dt.Add(d);
            }
            */
            DocumentTypes.Add(dt);
        }
    }
}
